package com.qfedu.edu.service.auto;

import com.qfedu.edu.service.IJwtService;
import com.qfedu.edu.service.ITokenService;
import com.qfedu.edu.service.impl.JwtService;
import com.qfedu.edu.service.impl.TokenService;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author wangchen
 * @title: JwtTokenServiceAutoConfiguration
 * @projectName cd-fy-2401-third-project-parent
 * @description: 这个就是jwt的自动配置
 * @date 2024/9/13  15:38
 */
@SpringBootConfiguration
@EnableConfigurationProperties(JwtTokenServiceProperties.class)
@ConditionalOnClass({JwtService.class, TokenService.class})
public class JwtTokenServiceAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    public IJwtService jwtService(JwtTokenServiceProperties jwtTokenServiceProperties) {
        JwtService jwtService = new JwtService();
        jwtService.setSign(jwtTokenServiceProperties.getSign());
        return jwtService;
    }


    @Bean
    @ConditionalOnMissingBean
    public ITokenService tokenService(JwtTokenServiceProperties jwtTokenServiceProperties) {
        TokenService tokenService = new TokenService();
        tokenService.setSign(jwtTokenServiceProperties.getSign());
        tokenService.setExpire(jwtTokenServiceProperties.getExpire());
        return tokenService;
    }


}
